package org.ytor.core.sqlflow;

import org.ytor.core.sqlflow.builder.support.DeleteBuilder;
import org.ytor.core.sqlflow.builder.support.InsertBuilder;
import org.ytor.core.sqlflow.builder.support.UpdateBuilder;
import org.ytor.core.sqlflow.builder.select.SelectBuilder;
import org.ytor.core.sqlflow.builder.select.SelectStage;

/**
 * created by yangtong on 2025/8/7 20:06:22
 * <br/>
 * 数据库操作入口
 */
public class SQLHelper {

    @SafeVarargs
    public static <T> SelectStage select(SFunction<T, ?>... field) {
        return new SelectBuilder().select(field);
    }

    public static <A> SelectStage select(SFunction<A, ?> field1) {
        return new SelectBuilder().select(field1);
    }

    public static <A, B> SelectStage select(SFunction<A, ?> field1, SFunction<B, ?> field2) {
        return new SelectBuilder().select(field1, field2);
    }

    public static <A, B, C> SelectStage select(SFunction<A, ?> field1, SFunction<B, ?> field2, SFunction<C, ?> field3) {
        return new SelectBuilder().select(field1, field2, field3);
    }

    public static <A, B, C, D> SelectStage select(SFunction<A, ?> field1, SFunction<B, ?> field2, SFunction<C, ?> field3, SFunction<D, ?> field4) {
        return new SelectBuilder().select(field1, field2, field3, field4);
    }

    public static <A, B, C, D, E> SelectStage select(SFunction<A, ?> field1, SFunction<B, ?> field2, SFunction<C, ?> field3, SFunction<D, ?> field4, SFunction<E, ?> field5) {
        return new SelectBuilder().select(field1, field2, field3, field4, field5);
    }

    public static <A, B, C, D, E, F> SelectStage select(SFunction<A, ?> field1, SFunction<B, ?> field2, SFunction<C, ?> field3, SFunction<D, ?> field4, SFunction<E, ?> field5, SFunction<F, ?> field6) {
        return new SelectBuilder().select(field1, field2, field3, field4, field5, field6);
    }

    public static <A, B, C, D, E, F, G> SelectStage select(SFunction<A, ?> field1, SFunction<B, ?> field2, SFunction<C, ?> field3, SFunction<D, ?> field4, SFunction<E, ?> field5, SFunction<F, ?> field6, SFunction<G, ?> field7) {
        return new SelectBuilder().select(field1, field2, field3, field4, field5, field6, field7);
    }

    /**
     * 查询数据
     */
    public static SelectStage selectRaw(String... fields) {
        return new SelectBuilder().selectRaw(fields);
    }

    /**
     * 插入数据
     */
    public static <T extends PersistenceModel<T, ?>> InsertBuilder<T> insert() {
        return new InsertBuilder<T>();
    }

    /**
     * 更新数据
     */
    public static <T extends PersistenceModel<T, ?>> UpdateBuilder<T> update(Class<T> entityClass) {
        return new UpdateBuilder<>().update(entityClass);
    }

    /**
     * 删除数据
     */
    public static <T extends PersistenceModel<T, ?>> DeleteBuilder<T> delete() {
        return new DeleteBuilder<T>();
    }

}
